home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / lang / AmigaTalk.lha / general / Interval.st < prev    next >
Text File  |  2000-05-15  |  2KB  |  63 lines

  1. Class Interval :SequenceableCollection
  2. ! lower upper step current !
  3. [
  4.    from: lowerBound to: upperBound by: stepSize
  5.      current <- lower <- lowerBound.
  6.      upper   <- upperBound.
  7.      step    <- stepSize
  8. |  
  9.    size   
  10.      ^ ((step strictlyPositive) 
  11.           ifTrue:  [upper < lower]
  12.           ifFalse: [lower < upper] )
  13.         ifTrue:  [ 0 ]
  14.         ifFalse: [upper - lower // step + 1]
  15. |  
  16.    inRange: value
  17.      ^ (step strictlyPositive)
  18.         ifTrue:  [(value >= lower) and: [value <= upper]]
  19.         ifFalse: [(value >= upper) and: [value <= lower]]
  20.    first
  21.      current <- lower.
  22.      ^ (self inRange: current) ifTrue: [current]
  23. |
  24.    last
  25.      current <- upper.
  26.      ^ (self inRange: current) ifTrue: [current]
  27. |   
  28.    next
  29.      current <- current + step.
  30.      ^ (self inRange: current) ifTrue: [current]
  31. |
  32.    at: index ifAbsent: exceptionBlock   ! val !
  33.      val <- lower + (step * (index - 1)).
  34.  
  35.      ^ (self inRange: val)
  36.          ifTrue: [ val ]
  37.         ifFalse: [exceptionBlock value]
  38.    printString
  39.      ^ 'Interval ', lower printString , ' to ',
  40.                     upper printString , ' by ' , step printString 
  41. |   
  42.    coerce: newcollection
  43.      ^ newcollection asArray
  44. |   
  45.    at: index put: val
  46.      ^ self error: 'cannot store into Interval'
  47. |   
  48.    add: val
  49.      ^ self error: 'cannot store into Interval'
  50. |   
  51.    removeKey: key ifAbsent: exceptionBlock
  52.      self error: 'cannot remove from Interval'.
  53.      ^ exceptionBlock value
  54. |
  55.    deepCopy
  56.      ^ lower to: upper by: step
  57. |   
  58.    shallowCopy
  59.      ^ lower to: upper by: step
  60. ]
  61.